package com.oocl.euc.service.impl;

import java.util.List;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oocl.euc.dao.DishDao;
import com.oocl.euc.dao.impl.DishDaoImpl;
import com.oocl.euc.dao.impl.MerchantDaoImpl;
import com.oocl.euc.entity.Dish;
import com.oocl.euc.service.DishService;
@Service("dishService")
@Transactional
public class DishServiceImpl implements DishService {
	@Autowired
	private DishDaoImpl dd;
	@Autowired
	private MerchantDaoImpl mdi;
	@Override
	public String addDish(Dish d, String mid) {
		d.setMerchant(mdi.findById(mid));
		dd.save(d);
		List<Dish> dishes=dd.findDishesByMid(mid);
		return dishes!=null?dishes.get(dishes.size()-1).getDid().toString():null;
		
	}

	@Override
	public Integer deleteDish(String did) {
		return dd.delete(findDishByDid(did));
	}

	@Override
	public List<Dish> findDishesByMid(String mid) {
		return dd.findDishesByMid(mid);
	}

	@Override
	public Dish findDishByDid(String did) {
		return dd.findById(did);
	}

	@Override
	public Integer updateDish(Dish d) {
		return dd.updateDish(d);
	}

	
	

}
